package com.zmn.plat.admin.controller.extension.category;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.zmn.plat.model.entity.extension.category.ExtensionCategory;
import com.zmn.plat.model.entity.extension.category.ExtensionCategoryQuery;

/**
 * 推广分类
 *
 * @author linfeng
 * @since 2019-12-24 10:55:48
 */
@Controller
@RequestMapping("/extension/category/")
public class ExtensionCategoryListController extends ExtensionCategoryBaseController {

    /**
     * 列表
     *
     * @param query
     * @author linfeng
     * @since 2019-12-24 10:55:48
     */
    @RequestMapping("list")
    @RequiresPermissions("/extension/category/list.action")
    public ModelAndView list(@ModelAttribute ExtensionCategoryQuery query) {

        List<ExtensionCategory> items = extensionCategoryService.listPageByQuery(query);

        ModelAndView mav = new ModelAndView("extension/category/list");
        mav.addObject("items", items);
        mav.addObject("vo", query);
        return mav;
    }

    /**
     * 详情
     *
     * @param categId
     * @author linfeng
     * @since 2019-12-24 10:55:48
     */
    @RequestMapping("detail")
    @RequiresPermissions("/extension/category/detail.action")
    public ModelAndView detail(@RequestParam(value = "categId", defaultValue = "0") Integer categId) {
        ExtensionCategory extensionCategory;
        if (categId == 0) {
            extensionCategory = new ExtensionCategory();
        } else {
            extensionCategory = extensionCategoryService.findByKey(categId);
        }

        ModelAndView mav = new ModelAndView("extension/category/detail");
        mav.addObject("categ", extensionCategory);
        return mav;
    }

}
